procedure siftup(i : longint);

var 
	t, k : longint;
  
begin
	k := i shr 1;
	while (i > 1) and (a[k] > a[i]) do begin
		t := a[i];
		a[i] := a[k];
		a[k] := t;
		i := k;
		k := i shr 1;
	end;
end;

procedure insert(v : longint);
begin
	inc(n);
	a[n] := v;
	siftup(n);
end;

procedure siftdown(i : longint);

var 
	j, t, k : longint;
	
begin
	k := i shl 1;
	while k <= n do begin
		j := i;
		if a[k] < a[j] then j := k;
		if (k + 1 <= n) and (a[k + 1] < a[j]) then j := k + 1;
		if i < j then begin
			t := a[i];
			a[i] := a[j];
			a[j] := t;
			i := j;
		end else break;
		k := i shl 1;
	end;
end;

function ex_min() : longint;
begin
	result := a[1];
	a[1] := a[n];
	dec(n);
	siftdown(1);
end;